<template>
    <div>
        <a-button-group class="addbutton">
            <button @click="addButton()"><i class="iconfont iconadd"></i></button>
            <button @click="removeBtns()"><i class="iconfont icontrash"></i></button>
            <button @click="moveBtnUp()"><i class="iconfont iconshang"></i></button>
            <button @click="moveBtnDown()"><i class="iconfont iconxia"></i></button>
            <button @click="moveTopUp()"><i class="iconfont iconzhiding"></i></button>
            <button @click="bottomUp()"><i class="iconfont iconzhidi"></i></button>
            <button @click="loadDefaultButton()">
                {{i18n('list.addDefault','添加默认')}}
            </button>

        </a-button-group>
            <rx-grid
                ref="buttonTable"
                :bordered="true"
                :showColumnsMenu="true"
                :dataSource="buttons"
                :columns="buttonColumns"
                :allowRowSelect="true"
                :heightAuto="true"
                :multiSelect="true"
                :showPage="false"
                style="width: 91.5%;"
            >
            <template slot="name" slot-scope="{text, record, index}">
                <a-input v-model="record.name" @change="updateI18nName(record,'name')">
                    <my-icon slot="addonAfter" type="iconearth-full" @click="editI18nName(record,'name')"/>
                </a-input>
            </template>

            <template slot="style" slot-scope="{text, record, index}">
                <a-select :options="buttonStyle" v-model="record.style">
                </a-select>
            </template>

            <template slot="type" slot-scope="{text, record, index}">
                <div v-if="showType(record.type)">
                    {{ record.type }}
                </div>

                <a-select v-else :options="buttonType" v-model="record.type" @change="changeBtnType(record)">
                </a-select>
            </template>

            <template slot="method" slot-scope="{text, record, index}">
                <div style="height: 25px;" v-if="record.preDef || record.type=='custom'">
                    {{ text }}
                </div>
                <template v-else>
                    <a-input v-model="record.method"></a-input>
                </template>
            </template>
            <template slot="config" slot-scope="{text,record,index}">
                <a-button v-show="record.needConfig" @click="configButton(record)">
                    {{$ti18('rxList.config','配置')}}
                </a-button>
            </template>
            <template slot="mode" slot-scope="{text,record,index}">
                <a-checkbox-group v-if="!record.needMode" v-model="record.modeConfig" :options="modeOptions" @change="needChange($event,record,'mode')" />
            </template>
            <template slot="terminal" slot-scope="{text,record,index}">
              <a-checkbox-group v-if="!record.needTerminal" v-model="record.terminalConfig" :options="terminalOptions" @change="needChange($event,record,'terminal')" />
            </template>
            <template slot="conditionConfig" slot-scope="{text,record,index}">
                <template v-if="getConfig(record,'conditionConfig')">
                    <a-button @click="configDef(record)"  type="primary" :title="i18n('list.configured','已配') ">
                        <a-icon type="edit" />
                    </a-button>
                </template>
                <template v-else>
                    <a-button @click="configDef(record)" :title="i18n('list.notConfigured','已配') " >
                        <a-icon type="edit"/>
                    </a-button>
                </template>
            </template>
            <template slot="preCondConfig" slot-scope="{text,record,index}">
                <template v-if="getConfig(record,'preCondConfig')">
                    <a-button @click="configPreDef(record)"  type="primary" :title="i18n('list.configured','已配') ">
                        <a-icon type="edit"/>
                    </a-button>
                </template>
                <template v-else>
                    <a-button @click="configPreDef(record)" :title="i18n('list.notConfigured','已配') " >
                        <a-icon type="edit"/>
                    </a-button>
                </template>
            </template>
        </rx-grid>
    </div>
</template>

<script>


import {Util, GridMixin,Dialog,I18Parse} from "@lowcode/jpaas-common-lib";
import FormPdfTemplateList from "../FormPdfTemplateList";
import FormUreportList from "@/views/modules/form/core/FormUreportList";
import FormSolutionOpenUreportDialog from "@/views/modules/form/core/FormSolutionOpenUreportDialog.vue";
import FormPrintLodopList from "@/views/modules/form/core/FormPrintLodopList";
import DialogBox from "@/assets/js/DialogBox";
import FormSolutionMappingConfig from "@/views/modules/form/core/FormSolutionMappingConfig";
import FormSolutionButtonMappingConfig from "../FormSolutionButtonMappingConfig";
import FormSolutionButtonPreMappingConfig from "../FormSolutionButtonPreMappingConfig";
import FormWordTemplateDialog from "@/views/modules/form/core/FormWordTemplateDialog";
import CustomControlDialog from "./CustomConfigDialog/CustomControlDialog.vue";

import FormSolutionConfigOpenListDialog from "@/views/modules/form/core/FormSolutionConfigOpenListDialog.vue";
import FormSolutionApi from "@/api/form/core/formSolution";
import OpenFormConfig from "@/views/modules/form/core/formsolution/CustomConfigDialog/OpenFormConfig";
import ExcelTemplateDialog from "@/views/modules/form/bo/ExcelTemplateDialog";
import FormLiteFlowDialog from "@/views/modules/form/bo/FormLiteFlowDialog";
import defaultButtonsLang from "@/locales/lang/impl/components/defaultButtonsLang.js"
import FormOpenCustomView from "@/views/modules/form/core/FormOpenCustomView";
export default {
    name: "SolutionButtonDef",
    mixins: [GridMixin,defaultButtonsLang],
    props: {
        buttons: {
            type: Array
        },
        form: {
            type: Object
        },
        pkId: {
            type: String
        },
        boAttrs: {
            type: Array
        }
    },
    data() {
        return {
            i18nDefault:process.env.VUE_APP_LANGUAGE,
            i18nCurrent:"",
            isInitI18n:false,
            defaultButtons: [
                {
                    name: this.deBtnI18n('submitApprove',"提交审批"),
                    method: "startFlow",
                    style: "primary",
                    idx_: 1,
                    needConfig: false,
                    type: "startFlow",
                    config: {},
                    preDef: true,
                    modeConfig:["edit"],
                    mode:"edit",
                    needMode:false,//隐藏适用页面
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    name: this.$ti18('rxForm.saveBtn','保存'),
                    method: "submit",
                    style: "default",
                    idx_: 2,
                    needConfig: false,
                    type: "submit",
                    config: {},
                    preDef: true,
                    modeConfig:["edit"],
                    mode:"edit",
                    needMode:false,//隐藏适用页面
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    name: this.deBtnI18n('newSubmit',"复制添加"),
                    method: "newSubmit",
                    style: "default",
                    idx_: 3,
                    needConfig: false,
                    type: "newSubmit",
                    config: {},
                    preDef: true,
                    modeConfig:["edit"],
                    mode:"edit",
                    needMode:false,//隐藏适用页面
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    name: this.$ti18('rxForm.print',"打印"),
                    method: "print",
                    style: "default",
                    idx_: 4,
                    needConfig: false,
                    type: "print",
                    config: {},
                    preDef: true,
                    modeConfig:["edit","detail"],
                    mode:"edit,detail",
                    needMode:false,//隐藏适用页面
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
                {
                    name: this.deBtnI18n('flowImage',"流程图"),
                    method: "flowImage",
                    style: "default",
                    idx_: 5,
                    needConfig: false,
                    type: "flowImage",
                    config: {},
                    preDef: true,
                    modeConfig:["edit","detail"],
                    mode:"edit,detail",
                    needMode:false,//隐藏适用页面
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    name: this.boentI18n('list.Staging','暂存"'),
                    method: "staging",
                    style: "default",
                    idx_: 6,
                    needConfig: false,
                    type: "staging",
                    config: {},
                    preDef: true,
                    modeConfig:["edit"],
                    mode:"edit",
                    needMode:false,//隐藏适用页面
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
                {
                    name: this.$ti18('rxList.editBtn',"编辑"),
                    method: "edit",
                    style: "default",
                    idx_: 7,
                    needConfig: false,
                    type: "edit",
                    config: {},
                    preDef: true,
                    needMode:true,
                    modeConfig:["detail"],
                    mode:"detail",
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    name: this.deBtnI18n('submitAndContinue',"提交并继续"),
                    method: "submitAndContinue",
                    style: "default",
                    idx_: 8,
                    needConfig: false,
                    type: "submitAndContinue",
                    config: {},
                    preDef: true,
                    modeConfig:["edit"],
                    mode:"edit",
                    needMode:true,//隐藏适用页面
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
            ],
            buttonType: [
                {
                    label: this.deBtnI18n('printLodop',"套打"),
                    value: "printLodop",
                    method: "printLodop",
                    needConfig: true,
                    preDef: true,
                    config: {defId: "", name: ""},
                    modeConfig:["edit","detail"],
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
                {
                    label: this.deBtnI18n('pdfPrint',"PDF打印(模板)"),
                    value: "pdfPrint",
                    method: "pdfPrint",
                    config: {defId: "", name: ""},
                    needConfig: true,
                    preDef: true,
                    modeConfig:["edit","detail"],
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
                {
                    label: this.deBtnI18n('ureportPrint',"报表"),
                    value: "ureportPrint",
                    method: "ureportPrint",
                    config: {defId: "", name: ""},
                    needConfig: true,
                    preDef: true,
                    modeConfig:["edit","detail"],
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    label: this.deBtnI18n('openSolutionForm',"打开表单"),
                    value: "openSolutionForm",
                    method: "openSolutionForm",
                    needConfig: true,
                    preDef: true,
                    config: {formAlias: "", formName: "", formConfig: "", boDefId: ""},
                    modeConfig:["edit","detail"],
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    label: this.deBtnI18n('openCustomList',"打开列表"),
                    value: "openCustomList",
                    method: "openCustomList",
                    needConfig: true,
                    preDef: true,
                    config: {formAlias: "", formName: "", formConfig: "", boDefId: ""},
                    modeConfig:["edit","detail"],
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {
                    label: this.deBtnI18n('goBack',"返回"),
                    value: "goBack",
                    method: "goBack",
                    needConfig: false,
                    preDef: true,
                    needTerminal:false,
                    terminal:"pc,mobile",
                    terminalConfig:["pc","mobile"]
                },
                {label: this.deBtnI18n('formMethod',"表单方法"), value: "formMethod", method: "", needConfig: false, preDef: false,needTerminal:false, terminal:"pc,mobile", terminalConfig:["pc","mobile"]},
                {label: this.deBtnI18n('custom',"自定义"), value: "custom", method: "", needConfig: true, config: {action: ""}, preDef: false,needTerminal:false, terminal:"pc,mobile", terminalConfig:["pc","mobile"]},
                {label: this.deBtnI18n('bpmPreview',"流程仿真"), value: "bpmPreview", method: "bpmPreview", config: {}, needConfig: false, preDef: true,modeConfig:["edit"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('wordPrint',"Word打印"), value: "wordPrint", method: "wordPrint", config: {templateId:"",boDefId: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('pdfDownload',"下载PDF"), value: "pdfDownload", method: "pdfDownload", config: {templateId:"",boDefId: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('openPdf',"打开PDF"), value: "openPdf", method: "openPdf", config: {templateId:"",boDefId: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('printPdf',"打印PDF"), value: "printPdf", method: "printPdf", config: {}, needConfig: false, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {
                    label: this.deBtnI18n('customControl',"自定义组件"),
                    value: "customControl",
                    method: "openCustomControl",
                    //配置 { "width": "600px", "height": "400px",   "shade": false, "model": true, "isMax": "YES" }
                    config: { "width": "600px", "height": "400px","model": true, "isMax": "YES" },
                    needConfig: true,//是否显示配置
                    preDef: true,//预定义
                    modeConfig:["edit"],
                    needTerminal:true,
                    terminal:"pc",
                    terminalConfig:["pc"]
                },
                {label: this.deBtnI18n('excelPrint',"Excel打印"), value: "excelPrint", method: "excelPrint", config: {templateId:"",boDefId: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('excelDialog',"打开Excel"), value: "excelDialog", method: "excelDialog", config: {templateId:"",boDefId: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
                {label: this.deBtnI18n('handleLiteFlow',"规则引擎"), value: "handleLiteFlow", method: "handleLiteFlow", config: {liteFlowId:"",liteFlowName: ""}, needConfig: true, preDef: true,modeConfig:["edit","detail"],needTerminal:false,  terminal:"pc,mobile", terminalConfig:["pc","mobile"]},
                {label:this.deBtnI18n('openCustomPage',"打开页面定制"), value: "openCustomView", method: "openCustomView", needConfig: true, preDef: true,needTerminal:true, terminal:"pc", terminalConfig:["pc"]},
            ],
            buttonStyle: [{value: 'primary', label: 'primary'}, {value: 'default', label: 'default'},
                {value: 'dashed', label: 'dashed'}, {value: 'danger', label: 'danger'}, {value: 'link', label: 'link'}],
            buttonColumns: [
                {title: this.boentI18n('form.name','名称'), dataIndex: 'name', scopedSlots: {customRender: 'name'}},
                {title: this.deBtnI18n('style','样式'), dataIndex: 'style', scopedSlots: {customRender: 'style'}},
                {title: this.i18n('form.type','类型'), dataIndex: 'type', scopedSlots: {customRender: 'type'}},
                {title: this.deBtnI18n('methodName','方法名'), dataIndex: 'method', scopedSlots: {customRender: 'method'}},
                {title: this.$ti18('rxList.config','配置'), dataIndex: 'config', scopedSlots: {customRender: 'config'}},
                {title: this.deBtnI18n('ApplicablePage','适用页面'), dataIndex: 'mode', scopedSlots: {customRender: 'mode'}},
                {title: this.deBtnI18n('ApplicableTerminal','适用端口'), dataIndex: 'terminal', scopedSlots: {customRender: 'terminal'}},
                {title: this.i18n('form.config','条件配置'), dataIndex: 'conditionConfig', scopedSlots: {customRender: 'conditionConfig'}},
                {title: this.deBtnI18n('preCondConfig','前置条件'), dataIndex: 'preCondConfig', scopedSlots: {customRender: 'preCondConfig'}}
            ],
            btnSelectedRowKeys: [],
            btnSelectedRows: [],
            modeOptions:[{label: this.$ti18('rxList.editBtn',"编辑"),value:'edit'},{label: this.$ti18('rxList.detailBtn',"明细"),value:'detail'}],
            terminalOptions:[{label: this.deBtnI18n('terminal.mobile',"移动端"),value:'mobile'},{label: this.deBtnI18n('terminal.pc',"PC端"),value:'pc'}]
        }
    },
    mounted() {
        if (!this.pkId) {
            this.loadDefaultButton();
        }else {
            this.isInitI18n=true;
            this.loadCurrentButton();
        }
    },
    created(){
        this.getCurrentI18n();
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formSolution",key);
        },
        boentI18n(name,text,key){
            return this.$ti18(name,text,"formBoEntity",key);
        },
        deBtnI18n(name,text,key){
            return this.$ti18(name,text,"formSolution.defaultBtns",key);
        },
        loadCurrentButton() {
            if(this.buttons.length==0){
                this.isInitI18n=false;
                return;
            }
            for (var i = 0; i < this.buttons.length; i++) {
                var btn = this.buttons[i];
                let i18nJson=this.getI18nJson(btn,'name');
                btn.name=i18nJson[this.i18nCurrent];
                btn.i18nJson=JSON.stringify(i18nJson);
            }
            this.isInitI18n=false;
        },
        getCurrentI18n(){
            this.i18nCurrent= window.localStorage.getItem("language");
            if(!this.i18nCurrent){
                this.i18nCurrent=this.i18nDefault;
            }

        },
        updateI18nName(record,text) {
            let i18nJson=this.getI18nJson(record,text);
            record[text] = i18nJson[this.i18nCurrent];
            record.i18nJson=JSON.stringify(i18nJson);
            let table = this.$refs.buttonTable;
            table.$forceUpdate();
        },
        getI18nJson(row,text){
            let i18nJson={};
            let i18nConf =row.i18nJson;
            if(i18nConf){
                i18nJson=JSON.parse(i18nConf);
                let val=i18nJson[this.i18nCurrent];
                if(!val || !this.isInitI18n){
                    i18nJson[this.i18nCurrent]=row[text];
                }
            }else {
                i18nJson[this.i18nCurrent] = row[text];
                i18nJson[this.i18nDefault] = row[text];
            }
            return i18nJson;
        },
        editI18nName(record,text) {
            let table = this.$refs.buttonTable;
            let self_ = this;
            let conifg = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                data: {
                    i18nJson: this.getI18nJson(record,text)
                }
            }
            Dialog.openI18nDialog(conifg, function (action, data) {
                record[text] = data[self_.i18nCurrent];
                record.i18nJson=JSON.stringify(data);
                table.$forceUpdate();
            });
        },
        getConfig(record,key){
            if(record[key]){
                let condition = JSON.parse(record[key]);
                if(condition.hasOwnProperty('javaCode') && condition['javaCode'] ||
                    condition.hasOwnProperty('easyCondition') && condition['easyCondition'].rules.length > 0
                ){
                    this.conditionColorClass = 'rx-yes-config'
                    return true;
                }
            }
            return false;
        },
        loadDefaultButton() {
            var ary = [];
            for (var i = 0; i < this.defaultButtons.length; i++) {
                var btn = this.defaultButtons[i];
                btn.i18nJson=JSON.stringify(this.getI18nJson(btn,'name'));
                this.setOtherDefaultI18nVal(btn);
                var isExist = false;
                for (var j = 0; j < this.buttons.length; j++) {
                    var method = this.buttons[j].method;
                    if (method == btn.method) {
                        //已经存在的按钮更新多语言字段
                        this.buttons[j].i18nJson=btn.i18nJson
                        isExist = true;
                    }
                }
                if (!isExist) {
                    ary.push(Util.deepClone(btn));
                }
            }
            this.buttons.push(...ary);

        },
        //设置中文、英文默认值
        setOtherDefaultI18nVal(btn){
            let langs=I18Parse.handleLanList();
            if(!langs || langs.length==0){
                return;
            }
            let self_=this;
            langs.forEach(lang=>{
                if(lang!=this.i18nCurrent){
                    let langVal=defaultButtonsLang[btn.method];
                    if(langVal){
                        let i18nJson= JSON.parse(btn.i18nJson);
                        i18nJson[lang]=langVal[lang];
                        btn.i18nJson=JSON.stringify(i18nJson);
                    }
                }
            })

        },
        addButton() {
            this.buttons.push({
                name: "",
                method: "",
                type: "",
                style: "default",
                idx_: Util.randomId(),
                needConfig: false,
                preDef: false,
                modeConfig:["edit"],
                mode:"edit",
                needTerminal:false,
                terminal:"pc",
                terminalConfig:["pc"]
            });
        },
        removeBtns() {
            var self_ = this;
            this.$confirm({
                title: this.$ti18('rxMsa.actionTips','操作提示'),
                zIndex: 20000,
                content: this.$ti18('rxMsa.delInfo','您确定需要删除选中的记录吗？'),
                okText: this.$ti18('rxForm.ackBtn','确认'),
                cancelText: this.$ti18('rxForm.cancelBtn','取消'),
                onOk() {
                    self_.$refs.buttonTable.removeRows();
                },
                onCancel() {
                }
            })
        },
        moveBtnUp() {
            this.$refs.buttonTable.moveUp();
        },
        moveBtnDown() {
            this.$refs.buttonTable.moveDown();
        },
        moveTopUp(){
            this.$refs.buttonTable.moveTopUp();
        },
        bottomUp(){
            this.$refs.buttonTable.moveBottomUp();
        },
        changeBtnType(record) {
            let aryType = this.buttonType.filter(item => {
                return record.type == item.value;
            });
            if (aryType.length > 0) {
                let btnType = Util.deepClone(aryType[0]);
                if(!record.name){
                    record.name = btnType.label;
                    let i18nJson={};
                    let i18nConf='{"zh-CN":"","en-US":""}'
                    if(i18nConf) {
                        var i18nLang = JSON.parse(i18nConf);
                        for (let i18 in i18nLang){
                            i18nJson[i18]=record.name;
                        }
                        record.i18nJson=JSON.stringify(i18nJson);
                    }
                }
                delete btnType.label;
                Object.assign(record, btnType);
            }
        },
        onBtnSelectChange(selectedRowKeys, selectedRows) {
            this.btnSelectedRowKeys = selectedRowKeys;
            this.btnSelectedRows = selectedRows
        },
        configButton(row) {
            let type = row.type;
            let key = "func_" + type;
            if (!this[key]) {
                let msg = this.i18n('msg.PleaseDefine','请定义')+'[${key}]'+this.deBtnI18n('method','方法')
                this.$message.warning(msg);
                return;
            }
            this[key](row);
        },
        needChange(modeValue,row,field){
            row[field]=modeValue.join(',');
        },
        configPreDef(row){
            var boDefId = this.form.getFieldValue("bodefId");
            if (!boDefId) {
                this.$message.warning(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
                return;
            }
            var conf= {
                curVm:this,
                data:{config:row.preCondConfig,boDefId:boDefId},
                max:true,
                component:FormSolutionButtonPreMappingConfig,
                title: this.deBtnI18n('btn',"按钮")+this.deBtnI18n('preCondConfig',"前置条件")
            };
            var self_=this;
            Util.open(conf,function(action,data){
                if(action!='ok')return;
                row.preCondConfig=data;
                self_.$refs.buttonTable.$forceUpdate();
            })
        },
        configDef(row){
            var boDefId = this.form.getFieldValue("bodefId");
            if (!boDefId) {
                this.$message.warning(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
                return;
            }
            var conf= {
                curVm:this,
                data:{config:row.conditionConfig,boDefId:boDefId},
                max:true,
                component:FormSolutionButtonMappingConfig,
                title:this.deBtnI18n('btn',"按钮")+this.i18n('form.config',"条件配置")
            };
            var self_=this;
            Util.open(conf,function(action,data){
                if(action!='ok')return;
                row.conditionConfig=data;
                self_.$refs.buttonTable.$forceUpdate();
            })
        },
        /**
         * 配置套打
         */
        func_printLodop(row) {
            var boDefId = this.form.getFieldValue("bodefId");
            var boDefName = this.form.getFieldValue("name");
            if (!boDefId) {
                this.$message.warning(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
                return;
            }
            var self = this;
            var form = JSON.parse(this.form.getFieldValue("form"));
            /*"data": {
                "formId": boDefId,
                    "formName": boDefName,
                    "boDefId": boDefId,
                    "allowEdit": false
            },*/
            var config = {
                "curVm": self,
                "data": {
                    "boId": boDefId,
                    "boName": boDefName,
                    "boDefId": boDefId,
                    "allowEdit": false
                },
                component: FormPrintLodopList,
                title: this.deBtnI18n('printLodopTem',"套打模板"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {defId: data.pkId, name: data.name};
            });
        },
        /**
         * 配置pdf打印。
         **/
        func_pdfPrint(row) {
            var self = this;
            var form = JSON.parse(this.form.getFieldValue("form"));
            var boDefId = this.form.getFieldValue("bodefId");
            var config = {
                "curVm": self,
                "data": {
                    "formId": form.value,
                    "formName": form.text,
                    "boDefId": boDefId,
                    "defId": row.config.defId,
                    "allowEdit": false
                },
                component: FormPdfTemplateList,
                title: this.deBtnI18n('pdfPrint',"PDF打印"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {defId: data.pkId, name: data.name};
            });
        },
        /**
         * 配置打开表单方案
         */
        func_openSolutionForm(row) {
            //当前表单方案模型id
            var curBoDefId = this.form.getFieldValue("bodefId");
            if (!curBoDefId) {
                this.$message.error(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
                return;
            }
            //formAlias:data.alias,formName:data.name,formConfig:"",boDefId:data.bodefId
            let conf = {
                component: OpenFormConfig,
                curVm: this,
                widthHeight: ['1000px', '700px'],
                //max:true,
                title:this.i18n('form.openFormConfig', '打开表单配置'),
                data: {
                    config:row.config,
                    curBoDefId:curBoDefId,
                }
            }
            let self = this;
            Util.open(conf, function (action, data) {
                if (action != "ok") return;
                row.config = data;
            });

        },
        /**
         * 配置打开表单(旧)
         */
        func_openCustomForm(row) {
            var oldBoDefId = this.form.getFieldValue("bodefId");
            if (!oldBoDefId) {
                this.$message.error(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
                return;
            }
            let config = row.config;
            let boDefId = config.boDefId;
            //formAlias:data.alias,formName:data.name,formConfig:"",boDefId:data.bodefId
            if (!boDefId) {
                let confSol = {curVm: this, widthHeight: ['800px', '600px'], data: {multiSelect: false}};
                var self_ = this;
                DialogBox.openSoution(confSol, function (data) {
                    config.formAlias = data.alias;
                    config.formName = data.name;
                    config.boDefId = data.bodefId;
                    self_.setForm(config, oldBoDefId);
                })
            } else {
                this.setForm(config, oldBoDefId);
            }
        },
        /**
         *配置打开列表
         */
        func_openCustomList(row){
            var self_=this
            let fieldDatas =self_.boAttrs.map(function (item) {
                item.value=item.fieldName;
                item.label=item.label;
                return item;
            })
            var conf = {
                curVm: self_,
                data: {conf: row.config.listConfig,fieldDts: fieldDatas?fieldDatas:[]},
                widthHeight: ['800px', '600px'],
                component: FormSolutionConfigOpenListDialog,
                title: this.i18n("list.listConfig","打开列表配置"),
            };
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                let fieldMap=JSON.parse(data.fieldMap);
                row.config = {boListId: data.boListId, name: data.name,alias:data.alias,params:fieldMap,callBack:data.callBack};
                row.config.listConfig = JSON.stringify(data);
            })

        },
        setForm(config, oldBoDefId) {
            var conf = {
                curVm: this,
                data: {formConfig: config.formConfig, boDefId: config.boDefId, oldBoDefId: oldBoDefId},
                widthHeight: ['1000px', '600px'],
                component: FormSolutionMappingConfig,
                title: this.i18n('list.comment','表单方案')+this.$ti18('rxList.config','配置')
            };
            //{formAlias:"",formName:"",formConfig:"",boDefId:""}
            Util.open(conf, function (action, data) {
                if (action != 'ok') return;
                config.formConfig = data;
            })
        },
        /**
         * 配置UReport报表。
         */
        func_ureportPrint(row) {
            var self = this;
            var form = JSON.parse(this.form.getFieldValue("form"));
            let conf = row.conf;
            if (!conf){
                conf={
                    params:[]
                }
            }else {
                if (row.conf.params==null){
                    conf.params=[];
                }
            }

            if (this.form.getFieldValue("alias")){
                var alias=this.form.getFieldValue("alias")
                conf.alias=alias;
            }else {
                conf.alias="";
            }
            var config = {
                "curVm": self,
                /* "data": {
                   "formId": form.value,
                   "formName":form.text,
                   "boDefId": boDefId,
                   "allowEdit":false
                 },*/
                "data": {
                    "allowEdit": false,
                    customConfig: conf
                },
                component: FormSolutionOpenUreportDialog,
                title: this.deBtnI18n('ureportPrint',"报表打印"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {defId: data.pkId, name: data.name};
                row.conf=data

            });
        },
        /**
         * 配置自定义方法。
         * @param row
         */
        func_custom(row) {
            let config = row.config;
            let oldBoDefId = this.form.getFieldValue("bodefId");
            let conf = {
                curVm: this,
                widthHeight: ['800px', '550px'],
                data: {action: config.action, boDefId: oldBoDefId}
            };
            DialogBox.openButtonFunConfig(conf, function (data) {
                config.action = data.action;
            })
        },
        //配置word打印
        func_wordPrint(row) {
            this.setTemplate(row);
        },
        //配置pdf下载
        func_pdfDownload(row) {
            this.setTemplate(row);
        },
        //配置PDF
        func_openPdf(row){
            this.setTemplate(row);
        },
        //设置模板
        setTemplate(row){
            let boDefId = this.form.getFieldValue("bodefId");
            var self=this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": boDefId,
                    "templateId":row.config.templateId
                },
                component: FormWordTemplateDialog,
                title: this.deBtnI18n('wordTemplate',"选择word模板"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:boDefId};
            });
        },
        func_customControl(row){
            let obj = {
                curVm:this,
                component:CustomControlDialog,
                title: this.deBtnI18n('openCustomControl',"打开自定义组件配置"),
                widthHeight: ['800px', '500px'],
                data:{
                    openConfig:row.config
                }
            }
            Util.open(obj, function (action, data) {
                if (action != 'ok') return;
                row.config = data
            });
        },
        showType(type){
            let btn=this.defaultButtons.find(item=>{
                if(item.type==type){
                    return true;
                }
            })
            if(btn){
                return true;
            }
            return false;
        },
        //配置excel打印
        func_excelPrint(row) {
            let boDefId = this.form.getFieldValue("bodefId");
            var self=this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": boDefId,
                    "templateId":row.config.templateId
                },
                component: ExcelTemplateDialog,
                title: this.deBtnI18n('excelTemplate',"excel模板"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:boDefId};
            });
        },
        //配置excel打印
        func_excelDialog(row) {
            let boDefId = this.form.getFieldValue("bodefId");
            var self=this;
            var config = {
                "curVm": self,
                data: {
                    "boDefId": boDefId,
                    "templateId":row.config.templateId
                },
                component: ExcelTemplateDialog,
                title: this.deBtnI18n('excelTemplate',"excel模板"),
                widthHeight: ['800px', '600px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {templateId: data.pkId,boDefId:boDefId};
            });
        },
        //配置规则引擎
        func_handleLiteFlow(row) {
            var self=this;
            var config = {
                "curVm": self,
                data: {
                    "liteFlowId":row.config.liteFlowId
                },
                component: FormLiteFlowDialog,
                title: this.deBtnI18n('handleLiteFlow',"规则引擎"),
                widthHeight: ['900px', '700px']
            };
            Util.open(config, function (action, data) {
                if (action != 'ok') return;
                row.config = {liteFlowId: data.pkId,liteFlowName:data.chainDesc};
            });
        },
      //页面定制
      func_openCustomView(row){
        var curBoDefId = this.form.getFieldValue("bodefId");
        if (!curBoDefId) {
          this.$message.error(this.$ti18('rxForm.formName',"请选择表单！",'','select'));
          return;
        }
        let config = row.config;
        var conf = {
          curVm: this,
          data: {pkId:curBoDefId,customConfig: config},
          widthHeight: ['800px', '600px'],
          component: FormOpenCustomView,
          title: this.deBtnI18n('pageConfig',"打开页面定制配置")

        };
        Util.open(conf, function (action, data) {
          if (action != 'ok') return;
            row.config = data
        })
      }
    },
    watch:{
        "buttons":function(val,oldVal){
            this.isInitI18n=true;
            this.loadCurrentButton();
        }
    }
}
</script>

<style scoped>
.rx-no-config{
    color: red;
}
.rx-yes-config{
    color: green;
}
</style>